﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CodeJam08
{
    class Program
    {
        static string current;
        static string val;
        static string source;
        static string dest;

        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string[] tmp = input.Split(' ');

            val = tmp[0];
            source = tmp[1];
            dest = tmp[2];

            current = dest[0].ToString();

            int numSteps = GetNumSteps();
            int limit = 0;
            int i, j;

            for (i = 0; ; i++)
            {
                limit = (int)Math.Pow(dest.Length, i);

                if(limit >= numSteps)
                    break;
            }

            current = CreateLimitValue(i-1);

            for (j = i; j < numSteps; j++)
                Increment(0);

            //for (j = i-1; j > 0; j++)
            //{
            //    string x = CreateLimitValue(j);
            //    string tmp1 = current;
            //    current = current.Replace(current.Substring(1), tmp1);
            //}

            Console.WriteLine(current);
        }

        private static string CreateLimitValue(int i)
        {
            return new string(dest[0], i) + dest[i].ToString();
        }

        static int GetNumSteps()
        {
            int power = val.Length - 1;
            int sum = 0;
            int sub = source.Length;
            int index = 0;

            for (int i = power; i >= 0; i--)
            {
                sum += source.IndexOf(val[index++]) * (int)(Math.Pow(sub, i));
            }

            return sum;
        }

        static void Increment(int index)
        {
            if (index > current.Length - 1)
            {
                current += dest[0];
                return;
            }

            char[] tmp = current.ToCharArray();
            tmp[index] = Next(current[index]);
            current = new string(tmp);

            if (current[index] == dest[0])
            {
                Increment(index+1);
            }
        }

        static char Next(char x)
        {
            if (dest.IndexOf(x) == dest.Length - 1)
                return dest[0];

            return dest[dest.IndexOf(x) + 1];
        }



    }
}
